package com.nc.solutions.rentacar.domain.tariff.impl;

import com.nc.solutions.rentacar.domain.car.ICar;
import com.nc.solutions.rentacar.domain.tariff.ITariff;
import com.nc.solutions.rentacar.domain.Money.impl.Money;
import com.nc.solutions.rentacar.domain.Money.util.Currency;

import java.util.Date;

public class Tariff implements ITariff {
    private ICar car;
    private Money taxRate;

    public Tariff(ICar car) {
        this.car = car;
        taxRate = new Money();
    }

    public Money getPrice(Date dateFrom, Date dateTo) {
        int days1 = (int)(dateFrom.getTime() / 86400000); //24 hours * 60 minutes * 60 secs * 1000 msecs
        int days2 = (int)(dateTo.getTime() / 86400000);

        int days = days2 - days1;

        //здесь, в зависимости от количества дней, мы могли бы запилить скидку

        Money result = new Money(days * taxRate.getValue(),Currency.EUR);
       // result.setValue(days * taxRate.getValue();

        return result;
    }

    public void setTax(Money taxRate) {
        this.taxRate = taxRate;
    }

    public ICar getCar() {
        return car;
    }
}
